<template>
  <edit-dialog :centerDialogVisible="visible" :tilte="title" width="500" @Cancel="handleCancel" @Submit="handleSubmit" :disabled="loading">
    <template #content>
      <el-form ref="approveFormRef" :model="form" :rules="rules">
        <el-form-item prop="examineOpinion" label="审批意见">
          <el-input v-model="form.examineOpinion" type="textarea" rows="3" maxlength="200" show-word-limit/>
        </el-form-item>
      </el-form>
    </template>
  </edit-dialog>
</template>

<script>
import OuterUser from "@/views/construction/project-application/componens/OuterUser";
import EditDialog from "@/components/editDialog/index.vue";
import {approveProject} from "@/api/construction-project/projectManage";
import store from "@/store";

export default {
  name: "ReviewProject",
  components: {OuterUser, EditDialog},
  data() {
    return {
      visible: false,
      form: {},
      title: '注意',
      rules: {
        examineOpinion: [
          {required: true, message: '请输入', trigger: ['blur', 'change']},
        ]
      },
      loading: false
    }
  },
  computed: {
    userInfo() {
      return store.state.user.userInfo
    },
  },
  methods: {
    open(row, title) {
      this.title = title
      this.visible = true
      this.form.projectId = row.id
      if (title === '通过')  {
        this.form.status = 1
      } else {
        this.form.status = 0
      }
      this.form.change = row.change
      this.form.approver = {
        id: this.userInfo.userId,
        name: this.userInfo.name,
        organId: this.userInfo.organId,
        organName: this.userInfo.organName,
      }
    },
    handleCancel() {
      this.$refs.approveFormRef.resetFields()
      this.visible = false
    },
    handleSubmit() {
      this.$refs.approveFormRef.validate((valid) => {
        if (valid) {
          console.log('测试重复提交')
          this.loading = true
          approveProject({...this.form}).then(res => {
            this.$message.success('操作成功')
            this.$router.back()
          }).finally(()=>{
            this.loading = false
          })
        }
      });
    },
  }
}
</script>

<style lang="less" scoped>
.add-outer-user {
  overflow: auto;
  padding-right: 10px;

  .add-row {
    display: flex;
    justify-content: space-between;
    align-items: center;

    .left {
      display: flex;
      justify-content: space-between;
      align-items: center;

      .block {
        height: 15px;
        width: 6px;
        background: #1caad5;
        margin-right: 10px;
      }
    }

    .right {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 16px;
      height: 16px;
      border-radius: 50%;
      border: 1px solid #1caad5;
      cursor: pointer;
    }
  }
}
</style>
